﻿
@{
    ViewBag.Title = "ArchiveAJ";
    Layout = "~/Views/Shared/_LayoutForEUI.cshtml";
    var listColumns = ViewBag.Columns as List<SGArchiveSystem7x.Models.CColumnsModel>;
    var listMJ = ViewBag.TableMJ as List<SGArchiveSystem7xDB.V_ArchiveWord>;
    var listDep = ViewBag.Dep as List<SGArchiveSystem7xDB.T_Deparetment>;//部门
}

<table id="ArchiveInit_ArchiveAJ_grid" class="easyui-datagrid" style="width:100%;" title="@ViewBag.TypeN" data-options="
       rownumbers:true,
       singleSelect:false,
       autoRowHeight:false,
       pagination:true,
       fitColumns:false,
       fit:true,
       striped:true,
       checkOnSelect:false,
       selectOnCheck:false,
       toolbar:'#ArchiveInit_ArchiveAJ_tb',
       collapsible:false,
       pageSize: @SGArchiveSystem7x.Models.CCommonsModels.PageSize,
       pageList:[10,15,20]">
    <thead frozen="true">
        <tr>
            <th data-options="field:'ck',checkbox:true"></th>
            @{foreach (var c in listColumns)
                {
                    if (c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                    }

                }
            }
        </tr>
    </thead>
    <thead>
        <tr>
            @{foreach (var c in listColumns)
                {
                    if (!c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                    }

                }
            }
        </tr>
    </thead>
</table>
<div id="ArchiveInit_ArchiveAJ_tb" style="padding:2px 5px;">
    <input type="text" class="easyui-textbox pull-left" label="@ViewBag.Text1" labelwidth="80px" labelalign="right" style="width:180px" id="ArchiveInit_ArchiveAJ_txtQueryDH" />
    <input type="text" class="easyui-textbox pull-left" label="@ViewBag.Text2" labelwidth="80px" labelalign="right" style="width:180px" id="ArchiveInit_ArchiveAJ_txtQueryND" />
    <input type="text" class="easyui-textbox pull-left" label="@ViewBag.Text3" labelwidth="80px" labelalign="right" style="width:180px" id="ArchiveInit_ArchiveAJ_txtQueryTM" />
    <select type="text" class="easyui-combobox pull-left" label="@ViewBag.Text4" labelwidth="80px" labelalign="right" style="width:230px" id="ArchiveInit_ArchiveAJ_cmbKStatus" data-options="editable:false" panelHeight="auto">
        @{ 
            if(SGArchiveSystem7x.Models.Language._nowLanguage == SGArchiveSystem7xDB._VersionLanguage._Chs)
            {
                <option value="-1">全部</option>
                <option value="1">在库</option>
                <option value="3">已出库</option>
            }
            else
            {
                <option value="-1">ALL</option>
                <option value="1">IN</option>
                <option value="3">OUT</option>
            }
        }
        
    </select>
    <a href="javascript:void(0);" id="ArchiveInit_ArchiveAJ_btnFristQuery" class="easyui-linkbutton button-blue" iconCls="icon-search" onclick="FastQuery()" style="width:110px;height:30px;">@ViewBag.Text5</a>
    @if (ViewBag.Add)
    {
        <a href="javascript:void(0);" id="ArchiveInit_ArchiveAJ_btnAdd" class="easyui-linkbutton button-blue" iconCls="icon-add" onclick="ADD()" style="width:110px;height:30px;">添加档案</a>
    }
    @if (ViewBag.Init)
    {
        <a href="javascript:void(0);" id="ArchiveInit_ArchiveAJ_btnInit" class="easyui-linkbutton button-blue" iconCls="icon-redo" onclick="INIT()" style="width:110px;height:30px;">档案发布</a>}
    @if (ViewBag.AllInit)
    {
        <a href="javascript:void(0);" id="ArchiveInit_ArchiveAJ_btnInitAll" class="easyui-linkbutton button-blue" iconCls="icon-redo" onclick="ALLINIT()" style="width:110px;height:30px;">档案全部发布</a>}
    @if (ViewBag.LSInit)
    {
        <a href="javascript:void(0);" id="ArchiveInit_ArchiveAJ_btnInit" class="easyui-linkbutton button-blue" iconCls="icon-redo" onclick="LSINIT()" style="width:110px;height:30px;">档案临时发布</a>}
    @if (ViewBag.AllLSInit)
    {
        <a href="javascript:void(0);" id="ArchiveInit_ArchiveAJ_btnInitAll" class="easyui-linkbutton button-blue" iconCls="icon-redo" onclick="ALLLSINIT()" style="width:140px;height:30px;">档案全部临时发布</a>}
    @if (ViewBag.Query)
    {
        <a href="javascript:void(0);" id="ArchiveInit_ArchiveAJ_btnQuery" class="easyui-linkbutton button-blue" iconCls="icon-search" onclick="Query()" style="width:110px;height:30px;">@ViewBag.Text6</a>}
    @if (ViewBag.DZBrr)
    {
        <!--<a href="javascript:void(0);" id="ArchiveInit_ArchiveAJ_btnInit" class="easyui-linkbutton button-blue" iconCls="icon-edit" onclick="Brr(1)" style="width:110px;height:30px;">电子借阅</a>-->}
    @if (ViewBag.STBrr)
    {
        <a href="javascript:void(0);" id="ArchiveInit_ArchiveAJ_btnInitAll" class="easyui-linkbutton button-blue" iconCls="icon-edit" onclick="Brr(2)" style="width:110px;height:30px;display:none">登记借出</a>
        <a href="javascript:void(0);" id="ArchiveInit_ArchiveAJ_btnInitAll" class="easyui-linkbutton button-blue" iconCls="icon-edit" onclick="BrrRG()" style="width:150px;height:30px;">@ViewBag.Text7</a>
        <a href="javascript:void(0);" id="ArchiveInit_ArchiveAJ_btnInitAll" class="easyui-linkbutton button-blue" iconCls="icon-edit" onclick="RuRG()" style="width:150px;height:30px;">@ViewBag.Text8</a>
    }
    @if (ViewBag.OUTBrr)
    {
        <!--<a href="javascript:void(0);" id="ArchiveInit_ArchiveAJ_btnQuery" class="easyui-linkbutton button-blue" iconCls="icon-edit" onclick="OUTBrr()" style="width:110px;height:30px;">外部人员借阅</a>-->}
    @if (ViewBag.DownLoad)
    {
        <!--<a href="javascript:void(0);" id="ArchiveInit_ArchiveAJ_btnQuery" class="easyui-linkbutton button-blue" iconCls="icon-print" onclick="DownLoad()" style="width:110px;height:30px;">导出xls</a>-->}
</div>
<div id="ArchiveInit_ArchiveAJ_winInfo" class="easyui-window" title="档案信息" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:800px;height:500px;padding:10px;" maximizable="false" minimizable="false">
    <iframe id="ArchiveInit_ArchiveAJ_frmInfo" src="" frameborder="0" scrolling="yes" width="100%" height="500px"></iframe>
</div>

<div id="ArchiveInit_ArchiveAJ_winQuery" class="easyui-window" title="@ViewBag.Text6" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:550px;height:550px;padding:10px;;overflow-y:hidden!important;" maximizable="false" minimizable="false">
    <iframe id="ArchiveInit_ArchiveAJ_frmQuery" src="" frameborder="0" scrolling="no" width="100%" height="100%"></iframe>
</div>
<div id="ArchiveInit_ArchiveAJ_winBrr" class="easyui-window" title="借阅" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:900px;height:500px;padding:10px;" maximizable="false" minimizable="false">
    <iframe id="ArchiveInit_ArchiveAJ_frmBrr" src="" frameborder="0" scrolling="yes" width="100%" height="460px"></iframe>
</div>
<div id="ArchiveInit_ArchiveAJ_winUpLoad" class="easyui-window" title="上传" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:400px;height:150px;padding:10px;" maximizable="false" minimizable="false">
    <iframe id="ArchiveInit_ArchiveAJ_frmUpLoad" src="" frameborder="0" scrolling="no" width="100%" height="80px"></iframe>
</div>
<script>
    var ARRViewDepartmentID = '@ViewBag.ViewDepartmentID';//查看电子文件
    var ARRPrintDepartmentID = '@ViewBag.PrintDepartmentID';//打印电子文件
    var ARRDownDepartmentID = '@ViewBag.DownDepartmentID';//下载电子文件
    var ARREditDepartmentID ='@ViewBag.EditDepartmentID';//编辑档案，除添加
    var Mj = @ViewBag.Mj;
    var TableMJ =@Html.Raw(Json.Encode(listMJ));
    var TableDEP =@Html.Raw(Json.Encode(listDep));
    var USER ='@ViewBag.USER';
    var QX = '@ViewBag.QX';//是否是管理员
    function GetMJValueByMJ(mj)//通过密级获取密级的值
    {
        for (var i = 0; i < TableMJ.length; i++)
        {
            if (TableMJ[i].WD_ID == mj) {
                return TableMJ[i].WD_VALUE;
            }
        }
        return -1;
    }
    function DepQX(AJDep, UserDep)//AJDep 档案所属部门, UserDep 用户可以处理的部门
    {
        var Udep = UserDep.split(',');
        for (var i = 0; i < Udep.length;i++)
        {
            if (Udep[i] === AJDep) {
                return true;
            } 
        }
        return false;
    }
    function MJQX(AJMJ)//AJMJ 档案自身密级
    {
        var MJValue = GetMJValueByMJ(Mj);
        if (MJValue >= AJMJ) {
            return true;
        }
        return false;
    }
    $(document).ready(function () {
        $('#ArchiveInit_ArchiveAJ_grid').datagrid({
            url: '/ArchiveInit/Get_ajaxArchiveList?where=&AJZT=' +@ViewBag.AJZT+'&ARID=' +@ViewBag.ARID+'&I05='+@ViewBag.I05,
            singleSelect: true,
            method: 'post',
            onLoadSuccess: function (data) {
                $('.pagination-page-list').hide();
            }
        });
        InitPagenation()
    });
    function INIT()//选中发布
    {
        var rows = $('#ArchiveInit_ArchiveAJ_grid').datagrid('getChecked');
        if (rows.length == 0) {
            $.messager.alert('提示！', '请选择要发布的档案!', 'info');
            return false;
        }
        else
        {
            $.messager.confirm('提示', '确定是否发布？', function (r) {
                if (r) {
                    var dh = [];
                    for (var i = 0; i < rows.length; i++) {
                        dh.push(rows[i].DH);
                    }
                    $.ajax({
                        url: "/ArchiveInit/InitArchive",
                        dataType: "text",
                        type: "post",
                        data: { 'dh': dh },
                        success: function (data) {
                            $.messager.alert('提示！', '发布成功!', 'info');
                            $('#ArchiveInit_ArchiveAJ_grid').datagrid('options').url = '/ArchiveInit/Get_ajaxArchiveList?where=&AJZT=&ARID';
                            $('#ArchiveInit_ArchiveAJ_grid').datagrid('load');
                        }
                    });
                }
            })
        }
    }
    function ALLINIT()//全部发布
    {
        $.messager.confirm('提示', '确定是否发布？', function (r) {
            if (r) {
                $.ajax({
                    url: "/ArchiveInit/InitArchive",
                    dataType: "text",
                    type: "post",
                    //data: { 'dh': dh },
                    success: function (data) {
                        $.messager.alert('提示！', '发布成功!', 'info');
                        $('#ArchiveInit_ArchiveAJ_grid').datagrid('options').url = '/ArchiveInit/Get_ajaxArchiveList?where=&AJZT=&ARID';
                        $('#ArchiveInit_ArchiveAJ_grid').datagrid('load');
                    }
                });
            }
        })
    }
    function LSINIT()//选中临时发布
    {
        var rows = $('#ArchiveInit_ArchiveAJ_grid').datagrid('getChecked');
        if (rows.length == 0) {
            $.messager.alert('提示！', '请选择要发布的档案!', 'info');
            return false;
        }
        else {
            $.messager.confirm('提示', '确定是否临时发布？', function (r) {
                if (r) {
                    var dh = [];
                    for (var i = 0; i < rows.length; i++) {
                        dh.push(rows[i].DH);
                    }
                    $.ajax({
                        url: "/ArchiveInit/LSInitArchive",
                        dataType: "text",
                        type: "post",
                        data: { 'dh': dh },
                        success: function (data) {
                            $.messager.alert('提示！', '发布成功!', 'info');
                            $('#ArchiveInit_ArchiveAJ_grid').datagrid('options').url = '/ArchiveInit/Get_ajaxArchiveList?where=&AJZT=&ARID';
                            $('#ArchiveInit_ArchiveAJ_grid').datagrid('load');
                        }
                    });
                }
            })
        }
    }
    function ALLLSINIT()//全部临时发布
    {
        $.messager.confirm('提示', '确定是否临时发布？', function (r) {
            if (r) {
                $.ajax({
                    url: "/ArchiveInit/LSInitArchive",
                    dataType: "text",
                    type: "post",
                    //data: { 'dh': dh },
                    success: function (data) {
                        $.messager.alert('提示！', '发布成功!', 'info');
                        $('#ArchiveInit_ArchiveAJ_grid').datagrid('options').url = '/ArchiveInit/Get_ajaxArchiveList?where=&AJZT=&ARID';
                        $('#ArchiveInit_ArchiveAJ_grid').datagrid('load');
                    }
                });
            }
        })
    }
    function DownLoad()
    {
        $.ajax({
            url: "/ArchiveInit/DownLoadxlsAJ",
            dataType: "text",
            type: "post",
            data: { 'archivetype': @ViewBag.ARID },
            success: function (data) {
                window.open(data);
            }
        });
    }
    function ADD() {
        document.getElementById('ArchiveInit_ArchiveAJ_frmInfo').src = '/ArchiveInit/ArchiveAJInfo?archivetype='+@ViewBag.ARID;
        $('#ArchiveInit_ArchiveAJ_winInfo').window('open');
    }
    function FastQuery() {
        var dh = $('#ArchiveInit_ArchiveAJ_txtQueryDH').val();
        var nd = $('#ArchiveInit_ArchiveAJ_txtQueryND').val();
        var tm = $('#ArchiveInit_ArchiveAJ_txtQueryTM').val();
        var kfzt = $('#ArchiveInit_ArchiveAJ_cmbKStatus').combobox('getValue');
        $('#ArchiveInit_ArchiveAJ_grid').datagrid('options').url = '/ArchiveInit/Get_ajaxArchiveFastQuery?dh=' + dh + '&tm=' + tm + '&nd=' + nd + '&kfzt=' + kfzt + '&ARID=' + @ViewBag.ARID;
        $('#ArchiveInit_ArchiveAJ_grid').datagrid('load');
        InitPagenation();
        $('#ArchiveInit_ArchiveAJ_grid').datagrid('options').pageNumber = 1;
    }
    function Query() {
        document.getElementById('ArchiveInit_ArchiveAJ_frmQuery').src = '/ArchiveInit/ArchiveAJQuery?archivetype='+@ViewBag.ARID;
        $('#ArchiveInit_ArchiveAJ_winQuery').window('open');
    }
    function upload(dh, mj, dep) {
        if (MJQX(GetMJValueByMJ(mj))) {
            if (DepQX(dep, ARREditDepartmentID)) {
                document.getElementById('ArchiveInit_ArchiveAJ_frmUpLoad').src = '/ArchiveInit/Upload_PDF?dh=' + dh;
                $('#ArchiveInit_ArchiveAJ_winUpLoad').window('open');
            }
            else { $.messager.alert('提示！', '没有权限上传!', 'info'); }
        }
        else { $.messager.alert('提示！', '档案密级过高,没有权限修改!', 'info');}
    }
    function Modify(id, mj, dep, bjqx, SJJLR) {
        if (bjqx == 0)
        {
            if (MJQX(GetMJValueByMJ(mj))) {
                if (DepQX(dep, ARREditDepartmentID)) {
                    $('#ArchiveInit_ArchiveAJ_winInfo').window({ 'title': '修改档案' });
                    document.getElementById('ArchiveInit_ArchiveAJ_frmInfo').src = '/ArchiveInit/ArchiveAJInfo?archivetype=' +@ViewBag.ARID+ '&id=' + id;
                    //document.getElementById('ArchiveInit_ArchiveAJ_winInfo').title = '修改档案';
                    $('#ArchiveInit_ArchiveAJ_winInfo').window('open');
                }
                else { $.messager.alert('提示！', '没有权限修改!', 'info'); }
            }
            else { $.messager.alert('提示！', '档案密级过高,没有权限修改!', 'info'); }
        }
        else if (bjqx == 1)
        {
            if (USER == SJJLR) {
                if (MJQX(GetMJValueByMJ(mj))) {
                    if (DepQX(dep, ARREditDepartmentID)) {
                        $('#ArchiveInit_ArchiveAJ_winInfo').window({ 'title': '修改档案' });
                        document.getElementById('ArchiveInit_ArchiveAJ_frmInfo').src = '/ArchiveInit/ArchiveAJInfo?archivetype=' +@ViewBag.ARID+ '&id=' + id;
                        //document.getElementById('ArchiveInit_ArchiveAJ_winInfo').title = '修改档案';
                        $('#ArchiveInit_ArchiveAJ_winInfo').window('open');
                    }
                    else { $.messager.alert('提示！', '没有权限修改!', 'info'); }
                }
                else { $.messager.alert('提示！', '档案密级过高,没有权限修改!', 'info'); }
            }
            else { $.messager.alert('提示！', '只有本人可以编辑!', 'info'); }
        }
        else
        {
            if (USER == SJJLR || QX == "1")//
            {
                if (MJQX(GetMJValueByMJ(mj))) {
                    if (DepQX(dep, ARREditDepartmentID)) {
                        $('#ArchiveInit_ArchiveAJ_winInfo').window({ 'title': '修改档案' });
                        document.getElementById('ArchiveInit_ArchiveAJ_frmInfo').src = '/ArchiveInit/ArchiveAJInfo?archivetype=' +@ViewBag.ARID+ '&id=' + id;
                        //document.getElementById('ArchiveInit_ArchiveAJ_winInfo').title = '修改档案';
                        $('#ArchiveInit_ArchiveAJ_winInfo').window('open');
                    }
                    else { $.messager.alert('提示！', '没有权限修改!', 'info'); }
                }
                else { $.messager.alert('提示！', '档案密级过高,没有权限修改!', 'info'); }
            }
            else { $.messager.alert('提示！', '只有本人或管理员可以编辑!', 'info'); }
        }
    }
    function formatDeparetment(value, row) {
        for (var i = 0; i < TableDEP.length; i++) {
            if (TableDEP[i].Dep_ID == value) {
                return TableDEP[i].Dep_Name;
            }
        }
    }
    function formatWordBody(value, row) {
        for (var i = 0; i < TableMJ.length; i++) {
            if (TableMJ[i].WD_ID == value) {
                return TableMJ[i].WD_NAME;
            }
        }
    }
    function formatDate(value, row) {
        if (value != null) {
            var time = new Date(parseInt(value.substr(6, 19)))//.toLocaleDateString();//13
            var month = (time.getMonth() + 1);
            if (month < 9)
                month = "0" + month;
            var day = time.getDate();
            if (day < 9)
                day = "0" + day;

            var hm = '';
            var hours = time.getHours(); var mint = time.getMinutes();
            if (hours == 0 && mint == 0)
                hm = '';
            else {
                if (hours < 9)
                    hours = "0" + hours;
                if (mint < 9)
                    mint = "0" + mint;

                hm = hours + ":" + mint;
            }


            return time.getFullYear() + "-" + month + "-" + day + " " + hm; ///+ ":" + time.getSeconds();
        }
        else {
            return "";
        }
    }
    function formatKFZT(value, row) {
        if (value == "1")
            return "<span style='color:blue'>在库</span>";
        else if (value == "2")
            return "<span style='color:red'>等待出库</span>";
        else if (value == "3")
            return "<span style='color:red'>已出库</span>";
        else
            return "<span style='color:red'>已销毁</span>";
    }
    function formatAJZT(value, row) {
        if (value == "1")
            return "<span style='color:blue'>正常</span>";
        else if (value == "0")
            return "<span style='color:red'>设备读取</span>";
        else if (value == "2")
            return "<span style='color:red'>人工操作</span>";
    }
    function formatFile(value, row) { 
        if (value == null || value == '')
            return "<span style='color:red'>无</span>";
        var mj = row.MJ;
        var dep = row.GDBM;
        var id = row.ID;
        var wjqx = row.wjqx;
        var SJJLR = row.SJJLR
        return "<a href='javascript:void(0)' onclick='showPdf(\"" + value + "\",\"" + mj + "\",\"" + dep + "\"," + id + "," + wjqx + ",\"" + SJJLR+ "\")'><img src='../Content/images/images.png'></img></a>";
    }
    function formatFB(value, row) {
        var dh = row.DH;
        return "<a href='javascript:void(0)' onclick='fb(\"" + dh + "\")'><img src='../Content/images/pencil.png' />&nbsp;发布</a>";
    }
    function formatLSFB(value, row) {
        var dh = row.DH;
        return "<a href='javascript:void(0)' onclick='lsfb(\"" + dh + "\")'><img src='../Content/images/pencil.png' />&nbsp;临时发布</a>";
    }
    function fb(dh) {
        $.messager.confirm('提示', '确定是否发布？', function (r) {
            if (r) {
                var DH = [];
                DH.push(dh);
                $.ajax({
                    url: "/ArchiveInit/InitArchive",
                    dataType: "text",
                    type: "post",
                    data: { 'dh': DH },
                    success: function (data) {
                        if (data == "1") {
                            $.messager.alert('提示！', '发布成功!', 'info');
                            $('#ArchiveInit_ArchiveAJ_grid').datagrid('options').url = '/ArchiveInit/Get_ajaxArchiveList?where=&AJZT=&ARID';
                            $('#ArchiveInit_ArchiveAJ_grid').datagrid('load');
                        }
                        else { $.messager.alert('提示！', '发布失败!', 'info'); }
                    }
                });
            }
        })
    }
    function lsfb(dh) {
        $.messager.confirm('提示', '确定是否发布？', function (r) {
            if (r) {
                var DH = [];
                DH.push(dh);
                $.ajax({
                    url: "/ArchiveInit/LSInitArchive",
                    dataType: "text",
                    type: "post",
                    data: { 'dh': DH },
                    success: function (data) {
                        if (data == "1") {
                            $.messager.alert('提示！', '发布成功!', 'info');
                            $('#ArchiveInit_ArchiveAJ_grid').datagrid('options').url = '/ArchiveInit/Get_ajaxArchiveList?where=&AJZT=&ARID';
                            $('#ArchiveInit_ArchiveAJ_grid').datagrid('load');
                        }
                        else { $.messager.alert('提示！', '发布失败!', 'info'); }
                    }
                });
            }
        })
    }
    function formatDel(value, row) {
        var dh = row.DH;
        var id = row.ID;
        var mj = row.MJ;
        var dep = row.GDBM;
        return "<a href='javascript:void(0)' onclick='del(" + id + ",\"" + dh + "\",\"" + mj + "\",\"" + dep + "\")'><img src='../Content/images/close.png' />&nbsp;删除</a>";
    }
    function del(id, dh, mj,dep) {//string ARID, string type, string dh, string aid
        if (MJQX(GetMJValueByMJ(mj))) {
            if (DepQX(dep, ARREditDepartmentID)) {
                $.messager.confirm('提示', '是否删除此档案', function (r) {
                    if (r) {
                        $.ajax({
                            url: "/ArchiveInit/OpArchiveAJ",
                            dataType: "text",
                            type: "post",
                            data: { 'dh': dh, 'type': '删除', 'ARID':@ViewBag.ARID, 'aid': id },
                            success: function (data) {
                                $('#ArchiveInit_ArchiveAJ_grid').datagrid('options').url = '/ArchiveInit/Get_ajaxArchiveList?where=&AJZT=&ARID';
                                $('#ArchiveInit_ArchiveAJ_grid').datagrid('load');
                            }
                        });
                    }
                })
            }
            else { $.messager.alert('提示！', '没有权限删除!', 'info');}
        }
        else { $.messager.alert('提示！', '档案密级过高,没有权限删除!', 'info');}
     }
    function formatEdit(value, row) {
        var id = row.ID;
        var mj = row.MJ;
        var dep = row.GDBM;
        var bjqx = row.bjqx
        var SJJLR = row.SJJLR;
        return "<a href='javascript:void(0)' onclick='Modify(\"" + id + "\",\"" + mj + "\",\"" + dep + "\"," + bjqx + ",\"" + SJJLR+ "\")'><img src='../Content/images/pencil.png' />&nbsp;修改</a>";
    }
    function formatUpload(value, row) {
        var dh = row.DH;
        var mj = row.MJ;
        var dep = row.GDBM;
        return "<a href='javascript:void(0)' onclick='upload(\"" + dh + "\",\"" + mj + "\",\"" + dep + "\")'><span><img src='../Content/images/AddToAlbum.png' width='16px' heigth='16px'>&nbsp;上传</span></a>";
    }
    function showPdf(value, mj, dep, id, wjqx, SJJLR)
    {
        //alert(id);
        if (wjqx == 0)
        {
            if (MJQX(GetMJValueByMJ(mj))) {
                if (DepQX(dep, ARRViewDepartmentID)) {
                    $.ajax({
                        url: '/Insiders/pdfpath',
                        dataType: "text",
                        type: "post",
                        data: { 'path': value, 'id': id },
                        success: function (data) {
                            if (data != "1") {
                                if (DepQX(dep, ARRPrintDepartmentID) && DepQX(dep, ARRDownDepartmentID))
                                    window.open('../../Content/generic/web/viewer.html?file=' + data + "&down=1&print=1");
                                else if (DepQX(dep, ARRPrintDepartmentID) == true && DepQX(dep, ARRDownDepartmentID) == false)
                                    window.open('../../Content/generic/web/viewer.html?file=' + data + "&down=1&print=0");
                                else if (DepQX(dep, ARRPrintDepartmentID) == true && DepQX(dep, ARRDownDepartmentID) == false)
                                    window.open('../../Content/generic/web/viewer.html?file=' + data + "&down=0&print=1");
                                else
                                    window.open('../../Content/generic/web/viewer.html?file=' + data + "&down=0&print=0");
                            }

                        }
                    });
                }
                else { $.messager.alert('提示！', '没有权限浏览!', 'info'); }
            }
            else { $.messager.alert('提示！', '档案密级过高，没有权限浏览!', 'info'); }
        }
        else if (wjqx == 1)
        {
            if (USER == SJJLR)//
            {
                if (DepQX(dep, ARRViewDepartmentID)) {
                    $.ajax({
                        url: '/Insiders/pdfpath',
                        dataType: "text",
                        type: "post",
                        data: { 'path': value, 'id': id },
                        success: function (data) {
                            if (data != "1") {
                                if (DepQX(dep, ARRPrintDepartmentID) && DepQX(dep, ARRDownDepartmentID))
                                    window.open('../../Content/generic/web/viewer.html?file=' + data + "&down=1&print=1");
                                else if (DepQX(dep, ARRPrintDepartmentID) == true && DepQX(dep, ARRDownDepartmentID) == false)
                                    window.open('../../Content/generic/web/viewer.html?file=' + data + "&down=1&print=0");
                                else if (DepQX(dep, ARRPrintDepartmentID) == true && DepQX(dep, ARRDownDepartmentID) == false)
                                    window.open('../../Content/generic/web/viewer.html?file=' + data + "&down=0&print=1");
                                else
                                    window.open('../../Content/generic/web/viewer.html?file=' + data + "&down=0&print=0");
                            }

                        }
                    });
                }
                else { $.messager.alert('提示！', '没有权限浏览!', 'info'); }
            }
            else { $.messager.alert('提示！', '只有本人可以修改!', 'info'); }
        }
        else
        {
            if (USER == SJJLR||QX=="1")//
            {
                if (DepQX(dep, ARRViewDepartmentID)) {
                    $.ajax({
                        url: '/Insiders/pdfpath',
                        dataType: "text",
                        type: "post",
                        data: { 'path': value, 'id': id },
                        success: function (data) {
                            if (data != "1") {
                                if (DepQX(dep, ARRPrintDepartmentID) && DepQX(dep, ARRDownDepartmentID))
                                    window.open('../../Content/generic/web/viewer.html?file=' + data + "&down=1&print=1");
                                else if (DepQX(dep, ARRPrintDepartmentID) == true && DepQX(dep, ARRDownDepartmentID) == false)
                                    window.open('../../Content/generic/web/viewer.html?file=' + data + "&down=1&print=0");
                                else if (DepQX(dep, ARRPrintDepartmentID) == true && DepQX(dep, ARRDownDepartmentID) == false)
                                    window.open('../../Content/generic/web/viewer.html?file=' + data + "&down=0&print=1");
                                else
                                    window.open('../../Content/generic/web/viewer.html?file=' + data + "&down=0&print=0");
                            }

                        }
                    });
                }
                else { $.messager.alert('提示！', '没有权限浏览!', 'info'); }
            }
            else { $.messager.alert('提示！', '只有本人或管理员可以修改!', 'info'); }
        }

    }
    ///初始化分页
    function InitPagenation() {
        //设置分页控件
        var p = $('#ArchiveInit_ArchiveAJ_grid').datagrid('getPager');
        $(p).pagination({
            onSelectPage: function (pageNumber, pageSize) {
                QueryPager(pageNumber, pageSize);
            }
        });
    }
    ///分页查询
    function QueryPager(num, size) {
        $('#ArchiveInit_ArchiveAJ_grid').datagrid('options').url = '/ArchiveInit/Get_ajaxArchiveListPager?num=' + num + '&size=' + size;
        $('#ArchiveInit_ArchiveAJ_grid').datagrid('reload');
        $('#ArchiveInit_ArchiveAJ_grid').datagrid('options').pageNumber = num;
        $('#ArchiveInit_ArchiveAJ_grid').datagrid('options').pageSize = size;
        return;
    }
    function CloseWinQueryGrid() {
        $('#ArchiveInit_ArchiveAJ_winQuery').window('close');
        $('#ArchiveInit_ArchiveAJ_grid').datagrid('options').url = '/ArchiveInit/Get_ajaxArchiveList?where=&ARID=';
        $('#ArchiveInit_ArchiveAJ_grid').datagrid('load');
        //QueryPager($('#ArchiveInit_ArchiveAJ_grid').datagrid('options').pageNumber, $('#ArchiveInit_ArchiveAJ_grid').datagrid('options').pageSize);
        InitPagenation();
        $('#ArchiveInit_ArchiveAJ_grid').datagrid('options').pageNumber = 1;
    }
    function ClosewinInfoGrid() {
        $('#ArchiveInit_ArchiveAJ_winInfo').window('close');
        //$('#ArchiveInit_ArchiveAJ_grid').datagrid('options').url = '/ArchiveInit/Get_ajaxArchiveList?where=&ARID=';
        //$('#ArchiveInit_ArchiveAJ_grid').datagrid('load');
        QueryPager($('#ArchiveInit_ArchiveAJ_grid').datagrid('options').pageNumber, $('#ArchiveInit_ArchiveAJ_grid').datagrid('options').pageSize);
    }
    function ClosewinUpLoadGrid() {
        $('#ArchiveInit_ArchiveAJ_winUpLoad').window('close');
        //$('#ArchiveInit_ArchiveAJ_grid').datagrid('options').url = '/ArchiveInit/Get_ajaxArchiveList?where=&ARID=';
        //$('#ArchiveInit_ArchiveAJ_grid').datagrid('load');
        QueryPager($('#ArchiveInit_ArchiveAJ_grid').datagrid('options').pageNumber, $('#ArchiveInit_ArchiveAJ_grid').datagrid('options').pageSize);
    }
    function ClosewinBrrGrid() {
        $('#ArchiveInit_ArchiveAJ_winBrr').window('close');
        //$('#ArchiveInit_ArchiveAJ_grid').datagrid('options').url = '/ArchiveInit/Get_ajaxArchiveList?where=&ARID=';
        //$('#ArchiveInit_ArchiveAJ_grid').datagrid('load');
        QueryPager($('#ArchiveInit_ArchiveAJ_grid').datagrid('options').pageNumber, $('#ArchiveInit_ArchiveAJ_grid').datagrid('options').pageSize);
    }
    function Brr(type)
    {
        var rows = $('#ArchiveInit_ArchiveAJ_grid').datagrid('getChecked');
        //alert(rows.length);
        //alert(type);
        if (type == 2) {
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].KFZT != '1') {
                    $.messager.alert('@ViewBag.Text9', '@ViewBag.Text10', 'info');
                    return false;
                }
            }
        }
        else {
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].DZWJ == '' || rows[i].DZWJ == null) {
                    $.messager.alert('@ViewBag.Text9', '@ViewBag.Text11', 'info');
                    return false;
                }
            }
        }
        if (rows.length == 0) {
            $.messager.alert('@ViewBag.Text9', '@ViewBag.Text11', 'info');
            return false;
        }
        else {
            var entities = [];
            for (var i = 0; i < rows.length; i++) {
                entities.push(rows[i]);
            }
            //alert(rows.length);
            $.ajax({
                url: '/Insiders/Add_BrrArchive',
                type: 'post',
                async: true,
                dataType: 'text',
                data: { 'jsonBrr': JSON.stringify(entities) },
                success: function (data) {
                    if (data == "1") {
                        if (type == 1) {
                            $('#ArchiveInit_ArchiveAJ_winBrr').window({ 'title': '电子借阅' });
                        }
                        else {
                            $('#ArchiveInit_ArchiveAJ_winBrr').window({ 'title': '@ViewBag.Text12' });
                        }
                        document.getElementById('ArchiveInit_ArchiveAJ_frmBrr').src = '/Insiders/BrrArchive?type=' + type;
                        $('#ArchiveInit_ArchiveAJ_winBrr').window('open');
                    }
                    else { $.messager.alert('@ViewBag.Text9', '@ViewBag.Text13', 'info');}
                }
            });
        }
    }

    function BrrRG() {
        var type = 2;
        var rows = $('#ArchiveInit_ArchiveAJ_grid').datagrid('getChecked');
        if (type == 2) {
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].KFZT != '1') {
                    $.messager.alert('@ViewBag.Text9', '@ViewBag.Text14', 'info');
                    return false;
                }
            }
        }
        else {
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].DZWJ == '' || rows[i].DZWJ == null) {
                    $.messager.alert('@ViewBag.Text9', '@ViewBag.Text15', 'info');
                    return false;
                }
            }
        }
        if (rows.length == 0) {
            $.messager.alert('@ViewBag.Text9', '@ViewBag.Text15', 'info');
            return false;
        }
        else {
            var entities = [];
            for (var i = 0; i < rows.length; i++) {
                entities.push(rows[i].ID);
            }
            //alert(rows.length);
            $.ajax({
                url: '/ArchiveInit/RGCK',
                type: 'post',
                async: true,
                dataType: 'text',
                data: { 'ids': entities },
                success: function (data) {
                    if (data == "1") 
                        QueryPager($('#ArchiveInit_ArchiveAJ_grid').datagrid('options').pageNumber, $('#ArchiveInit_ArchiveAJ_grid').datagrid('options').pageSize);
                    else if (data == "-99")
                        $.messager.alert('@ViewBag.Text9', '@ViewBag.Text16', 'info'); 
                    else { $.messager.alert('@ViewBag.Text9', '@ViewBag.Text17', 'info'); }
                }
            });
        }
    }

    function RuRG() {
        var type = 2;
        var rows = $('#ArchiveInit_ArchiveAJ_grid').datagrid('getChecked');
        if (type == 2) {
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].KFZT != '3') {
                    $.messager.alert('@ViewBag.Text9', '@ViewBag.Text18', 'info');
                    return false;
                }
            }
        }
        else {
            for (var i = 0; i < rows.length; i++) {
                if (rows[i].DZWJ == '' || rows[i].DZWJ == null) {
                    $.messager.alert('@ViewBag.Text9', '@ViewBag.Text19', 'info');
                    return false;
                }
            }
        }
        if (rows.length == 0) {
            $.messager.alert('@ViewBag.Text9', '@ViewBag.Text19', 'info');
            return false;
        }
        else {
            var entities = [];
            for (var i = 0; i < rows.length; i++) {
                entities.push(rows[i].ID);
            }
            //alert(rows.length);
            $.ajax({
                url: '/ArchiveInit/RGRK',
                type: 'post',
                async: true,
                dataType: 'text',
                data: { 'ids': entities },
                success: function (data) {
                    if (data == "1")
                        QueryPager($('#ArchiveInit_ArchiveAJ_grid').datagrid('options').pageNumber, $('#ArchiveInit_ArchiveAJ_grid').datagrid('options').pageSize);
                    else if (data == "-99")
                        $.messager.alert('@ViewBag.Text9', '@ViewBag.Text16', 'info');
                    else { $.messager.alert('@ViewBag.Text9', '@ViewBag.Text17', 'info'); }
                }
            });
        }
    }
</script>

